<template>
  <div class="mod-role">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.roleName" placeholder="日志名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button  type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="taskname"
        :show-overflow-tooltip="true"
        header-align="center"
        align="center"
        width="150"
        label="任务名称">
      </el-table-column>
      <el-table-column
        prop="tasktime"
        header-align="center"
        align="center"
        :show-overflow-tooltip="true"
        label="任务时间">
      </el-table-column>
      <el-table-column
        prop="exceptionmessage"
        header-align="center"
        align="center"
        :show-overflow-tooltip="true"
        label="异常信息">
      </el-table-column>
      <el-table-column
        prop="exceptionclassname"
        header-align="center"
        align="center"
        :show-overflow-tooltip="true"
        label="异常类">
      </el-table-column>
      <el-table-column
        prop="log_level"
        header-align="center"
        align="center"
        :show-overflow-tooltip="true"
        width="180"
        label="日志级别">
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row,scope.index)"
            v-hasPermi="['monitor:operlog:query']"
          >详细</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[8, 15, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

    <!-- 操作日志详细 -->
    <el-dialog title="操作日志详细" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" label-width="100px" size="mini">
        <el-row>
          <el-col :span="24">
            <!--<el-form-item label="任务id：">{{ form.id }}</el-form-item>-->
            <el-form-item
              label="任务名称："
            >{{ form.taskname }}</el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="异常进程：">{{ form.threadname }}</el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="日志级别：">{{form.log_level}}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="异常信息：">{{ form.exceptionmessage }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="任务时间：">{{ form.tasktime }}</el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="异常类：">{{ form.exceptionclassname }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="异常原因："><span style="color: red">{{ form.exceptionmessagecause }}</span></el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="日志内容：">{{form.data}}</el-form-item>
          </el-col>


        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="open = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data () {
    return {
      // 表单参数
      form: {},
      // 是否显示弹出层
      open: false,
      dataForm: {
        roleName: ''
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 8,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      dataListSelectionsNames:[]
    }
  },
  activated () {
    this.getDataList()
  },
  methods: {
    /** 详细按钮操作 */
    handleView(row) {
      this.open = true;
      this.form = row;
    },
    // 获取数据列表
    getDataList () {
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/tbssbusLog/list'),
        method: 'get',
        params: this.$http.adornParams({
          'page': this.pageIndex,
          'limit': this.pageSize,
          'key': this.dataForm.roleName
        })
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.dataList = data.page.records
          this.totalPage = data.page.total
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
      this.dataListLoading=false;
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getDataList()
    },
    // 多选
    selectionChangeHandle (val) {
      this.dataListSelections = val
    },
    // 新增 / 修改
    addOrUpdateHandle (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    },
    // 删除
    deleteHandle (id) {
      var ids = id ? [id] : this.dataListSelections.map(item => {
        return item.id
      })
      var names = this.dataListSelections.map(item => {
        return item.taskname
      })
      /*this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {*/
      this.$confirm(`确定对[任务名称=${names.join(',')}]进行'删除'操作?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http({
          url: this.$http.adornUrl('/tbssbusLog/deletes'),
          method: 'post',
          data: this.$http.adornData(ids, false)
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.getDataList()
              }
            })
          } else {
            this.$message.error(data.msg)
          }
        })
      }).catch(() => {})
    }
  }
}
</script>
